package com.example.com.hupu.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.com.hupu.R;
import com.example.com.hupu.adapter.VideoAdapter;
import com.example.com.hupu.bean.NBALive;
import com.example.com.hupu.bean.VideoData;
import com.example.com.hupu.net.RetrofitNewsUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * NBA模块的Fragment
 */
public class VideoFragment extends Fragment {

    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;
    Unbinder unbinder;
    private List<NBALive> mNewsItems;

    private VideoAdapter mAdapter;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_nba, null);
        unbinder = ButterKnife.bind(this, view);

        getNBANews();
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

        return view;
    }

    private void getNBANews() {
        RetrofitNewsUtils.getApiService().getMatchVideo("100000:6157")
                .enqueue(new Callback<VideoData>() {
                    @Override
                    public void onResponse(Call<VideoData> call, Response<VideoData> response) {
                        VideoData videoData = response.body();
                        mAdapter = new VideoAdapter(videoData.data);
                        recyclerView.setAdapter(mAdapter);
                    }

                    @Override
                    public void onFailure(Call<VideoData> call, Throwable t) {

                    }
                });
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
